package com.medi.chats.utils;

import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * 描述:
 * 用户登录浏览器判断
 *
 * @outhor Administrator
 * @create 2018-11-08 13:31
 */
@Service
public class UserAgentUtil {

    /**
     * @Description  判断 移动端/PC端
     * @Author        Administrator
     * @Date          2018/11/8 13:33
    */
    public static boolean isMobile(HttpServletRequest request) {
        List<String> mobileAgents = Arrays.asList("ipad", "iphone os", "rv:1.2.3.4", "ucweb", "android", "windows ce", "windows mobile");
        String ua = request.getHeader("User-Agent").toLowerCase();
        for (String sua : mobileAgents) {
            if (ua.indexOf(sua) > -1) {
                return true;//手机端
            }
        }
        return false;//PC端
    }

    /**
     * @Description  是否微信浏览器
     * @Author        Administrator
     * @Date          2018/11/8 13:32
    */
    public static boolean isWechat(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent").toLowerCase();
        if (ua.indexOf("micromessenger") > -1) {
            return true;//微信
        }
        return false;//非微信手机浏览器
    }
}
